#!/bin/sh
#
# should use retrovol 0.14.1+
#

for i in $@ ; do
	case $1 in
		-sysroot) SYSROOT=$2 ; shift 2 ;;
		-*) echo "unknown option: $i" ; shift ;;
	esac
done

if [ "$1" ] ; then
	TRAY_ICON_COLOR=$1
else
	if [ -f ${SYSROOT}$HOME/.config/retrovol_tray_color ] ; then
		read -r COLORX < ${SYSROOT}$HOME/.config/retrovol_tray_color
		COLORX="--init-color $COLORX"
	fi
	TRAY_ICON_COLOR="$(yad --color $COLORX)"
fi

if [ ! "$TRAY_ICON_COLOR" ] ; then
	exit 1
fi

echo "Retrovol Tray Icon Color: $TRAY_ICON_COLOR"

mkdir -p ${SYSROOT}/usr/share/retrovol/images
mkdir -p ${SYSROOT}$HOME/.config

echo "Writing config to ${SYSROOT}$HOME/.config/retrovol_tray_color"
echo -n "$TRAY_ICON_COLOR" > ${SYSROOT}$HOME/.config/retrovol_tray_color
OUTDIR=${SYSROOT}/usr/share/retrovol/images

echo "Creating ${OUTDIR}/audio-volume-high.svg"
echo '<?xml version="1.0" encoding="UTF-8"?>
<svg height="100" width="100" version="1.0">
	<polygon 
        points="10 60,  10 40,  20 40,  40 25, 40 75, 20 60, 10 60"
        style="fill: '${TRAY_ICON_COLOR}'; fill-opacity: 0.5; stroke: '${TRAY_ICON_COLOR}';
            stroke-width: 2;"/> 
    <path d="m 55,27 c 24,23 0,48 0,48" style="fill:none;stroke:'${TRAY_ICON_COLOR}';stroke-width:7"/>
    <path d="M 63,15 C 100,53 62,88 62,88" style="fill:none;stroke:'${TRAY_ICON_COLOR}';stroke-width:7"/>
    <path d="M 72,5 C 120,54 73,97 73,97" style="fill:none;stroke:'${TRAY_ICON_COLOR}';stroke-width:7"/>
</svg>' > ${OUTDIR}/audio-volume-high.svg

echo "Creating ${OUTDIR}/audio-volume-low.svg"
echo '<?xml version="1.0" encoding="UTF-8"?>
<svg height="100" width="100" version="1.0">
	<polygon 
        points="10 60,  10 40,  20 40,  40 25, 40 75, 20 60, 10 60"
        style="fill: '${TRAY_ICON_COLOR}'; fill-opacity: 0.5; stroke: '${TRAY_ICON_COLOR}';
            stroke-width: 2;"/> 
    <path d="m 55,27 c 24,23 0,48 0,48" style="fill:none;stroke:'${TRAY_ICON_COLOR}';stroke-width:7"/>
</svg>' > ${OUTDIR}/audio-volume-low.svg

echo "Creating ${OUTDIR}/audio-volume-medium.svg"
echo '<?xml version="1.0" encoding="UTF-8"?>
<svg height="100" width="100" version="1.0">
	<polygon 
        points="10 60,  10 40,  20 40,  40 25, 40 75, 20 60, 10 60"
        style="fill: '${TRAY_ICON_COLOR}'; fill-opacity: 0.5; stroke: '${TRAY_ICON_COLOR}';
            stroke-width: 2;"/> 
    <path d="m 55,27 c 24,23 0,48 0,48" style="fill:none;stroke:'${TRAY_ICON_COLOR}';stroke-width:7"/>
    <path d="M 63,15 C 100,53 62,88 62,88" style="fill:none;stroke:'${TRAY_ICON_COLOR}';stroke-width:7"/>
</svg>' > ${OUTDIR}/audio-volume-medium.svg

echo "Creating ${OUTDIR}/audio-volume-muted.svg"
echo '<?xml version="1.0" encoding="UTF-8"?>
<svg height="100" width="100" version="1.0">
	<polygon 
        points="10 60,  10 40,  20 40,  40 25, 40 75, 20 60, 10 60"
        style="fill: '${TRAY_ICON_COLOR}'; fill-opacity: 0.5; stroke: '${TRAY_ICON_COLOR}';
            stroke-width: 2;"/> 
    <line x1="5" y1="75" x2="60" y2="20" style="fill:none;stroke:red;stroke-width:7"/>
</svg>' > ${OUTDIR}/audio-volume-muted.svg

echo "Creating ${OUTDIR}/audio-volume-none.svg"
echo '<?xml version="1.0" encoding="UTF-8"?>
<svg height="100" width="100" version="1.0">
	<polygon 
        points="10 60,  10 40,  20 40,  40 25, 40 75, 20 60, 10 60"
        style="fill: '${TRAY_ICON_COLOR}'; fill-opacity: 0.5; stroke: '${TRAY_ICON_COLOR}';
            stroke-width: 2;"/>
</svg>' > ${OUTDIR}/audio-volume-none.svg

### END ###
